using System;
using System.Collections.Generic;
using System.Text;
using BizTalkCop.Rules.Bases;
using Microsoft.FxCop.Sdk;
using BizTalkCop.Rules.Enums;
using System.Xml.XPath;
using System.Xml;

namespace BizTalkCop.Rules.Naming.Rules
{
    /// <summary>
    /// Rule verifying expression shapes are correctly named
    /// </summary>
    public class ExpressionShapesShouldBePascalCased : OrchestrationRuleBase
    {
        /// <summary>
        /// Default constructor
        /// </summary>
        public ExpressionShapesShouldBePascalCased() : base("ExpressionShapesShouldBePascalCased") { }

        /// <summary>
        /// Checks if the expression is Pascal cased
        /// </summary>
        /// <param name="type">Type to check</param>
        /// <returns>Problem collection</returns>
        public override ProblemCollection Check(TypeNode type)
        {
            if (IsOrchestration(type))
            {
                //get the Expression shapes:
                XPathNodeIterator shapes = GetShapeInfos(type, ShapeType.VariableAssignmentShape);
                foreach (XPathNavigator shapeNavigator in shapes)
                {
                    string shapeName = shapeNavigator.SelectSingleNode(XPathQuery.ShapeTextNode).Value;
                    if (!MemberName.IsPascalCase(shapeName))
                    {
                        Problems.Add(new Problem(GetNamedResolution("Case", shapeName, MemberName.ToPascalCase(shapeName)), type));
                    }
                }  
            }
            return Problems;
        }

    }
}
